package com.example.myapplication.main

import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.viewModels
import com.example.myapplication.databinding.ActivityMainBinding
import com.example.myapplication.list.MyListActivityBase
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.hades.corelib.base.view.CoreActivity
import org.hades.corelib.base.vm.CoreViewModel

@AndroidEntryPoint
class MainActivity : CoreActivity() {

    private val viewModel: MainViewModel by viewModels()
    private lateinit var viewBinding:ActivityMainBinding

    override fun initByViewBind(layoutInflater: LayoutInflater, viewGroup: ViewGroup?): ViewGroup {
        viewBinding = ActivityMainBinding.inflate(layoutInflater)
        return viewBinding.root
    }

    override fun onGetViewModel(): CoreViewModel {
        return viewModel
    }

    override fun onCreateView(){

    }

    fun launchOnStarted(scope: CoroutineScope) {
        scope.launch {
            viewModel.uiFlow
                .collect{
                    Toast.makeText(baseContext, javaClass.name+it.str, Toast.LENGTH_SHORT).show()
                }
        }
    }

    override fun onCreateViewEvent() {
        viewBinding.mbAction.setOnClickListener {
//            viewModel.sendStateFlowMessage()
//            viewModel.getCash()
            startActivity(Intent(baseContext, MyListActivityBase::class.java))
        }
    }

}